package team.lourd.network.system.own.controller.netel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.data.web.PagedResourcesAssembler;
import org.springframework.hateoas.PagedResources;
import org.springframework.web.bind.annotation.*;
import team.lourd.network.system.annotation.JsonArg;
import team.lourd.network.system.own.domain.netel.NEBranch;
import team.lourd.network.system.own.domain.netel.NEFlowChart;
import team.lourd.network.system.own.domain.netel.NEModel;
import team.lourd.network.system.own.message.Result;
import team.lourd.network.system.own.repository.jpa.netel.NEBranchRepository;
import team.lourd.network.system.own.service.INEModelService;
import team.lourd.network.system.own.service.NetworkElementService;

@RestController
@RepositoryRestController
@RequestMapping(value = "/nEModels/manager")
public class NEModelManagerController {

    @Autowired
    private NEBranchRepository NEBranchRepository;

    @Autowired
    private INEModelService neModelService;

    @Autowired
    private NetworkElementService networkElementService;

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public @ResponseBody long saveModel(@JsonArg("model") NEModel model, @JsonArg("branch") NEBranch branch, @JsonArg("flowChart") NEFlowChart flowChart) {
        return neModelService.save(model, branch, flowChart);
    }

    // 运行
    @PostMapping("/run")
    public @ResponseBody Result handle(@JsonArg("flowChart") NEFlowChart flowChart) {
        return null;
    }

    @RequestMapping(value = "{id}/branches", method = RequestMethod.GET)
    public @ResponseBody PagedResources getAllByTeam(@PathVariable long id, Pageable pageable, PagedResourcesAssembler assembler, PersistentEntityResourceAssembler persistentEntityResourceAssembler) {
        Page<NEBranch> branches = NEBranchRepository.findById(id,pageable);
        return assembler.toResource(branches, persistentEntityResourceAssembler);
    }
}
